home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / misc / emu / ATUtilities.lha / ATUtilities / tdi.c < prev    next >
C/C++ Source or Header  |  2000-09-26  |  39KB  |  1,623 lines

  1. /* ******************************************************************* */
  2. /* **                                                               ** */
  3. /* **                     ATUtilities Disk Transfer                 ** */
  4. /* **            Copright (C) 1992-1993 by Thomas Dreibholz         ** */
  5. /* **                      All rights reserved                      ** */
  6. /* **                                                               ** */
  7. /* ******************************************************************* */
  8.  
  9. ULONG xxx=0;
  10.  
  11.  
  12. #include <devices/trackdisk.h>
  13. #include "janus.h"
  14. #include "ATUtilities.h"
  15.  
  16. #define REGISTER_NOPROGS
  17. #include "register.h"
  18.  
  19. #define BIT15 (1<<15)
  20.  
  21. struct UDevice
  22. {
  23.  UBYTE              Name[100];
  24.  UWORD              Unit;
  25.  ULONG              Heads;
  26.  ULONG              SectorsPerTrack;
  27.  ULONG              Tracks;
  28.  UWORD              Motor;
  29.  BOOL               File;
  30. };
  31.  
  32. struct CacheBlock
  33. {
  34.  ULONG  Changes;
  35.  ULONG  Offset;
  36.  UWORD  Length;
  37.  UBYTE *Memory;
  38.  UBYTE *NextCacheBlock;
  39. };
  40.  
  41. struct TDevice
  42. {
  43.  BOOL               Valid;
  44.  ULONG              Changes;
  45.  struct FileHandle *FileHandle;
  46.  struct IOStdReq   *Request;
  47.  struct MsgPort    *Port;
  48.  LONG               Device;
  49.  struct CacheBlock *FirstCacheBlock;
  50.  struct Remember   *CacheRemember;
  51. };
  52.  
  53. struct UDevice ud[6]=
  54. {
  55.  "trackdisk.device",0,2,11,80,4,FALSE,
  56.  "trackdisk.device",1,2,11,80,4,FALSE,
  57.  "trackdisk.device",0,1,11,80,4,FALSE,
  58.  "trackdisk.device",1,1,11,80,4,FALSE,
  59.  "DH0:Trashcan/File01",0,2,11,80,0,TRUE,
  60.  "DH0:Trashcan/File02",0,4,16,200,0,TRUE
  61. };
  62.  
  63. struct TDevice td[6]=
  64. {
  65.  TRUE,10000000L,NULL,NULL,NULL,-1L,0L,0L,
  66.  TRUE,10000000L,NULL,NULL,NULL,-1L,0L,0L,
  67.  TRUE,10000000L,NULL,NULL,NULL,-1L,0L,0L,
  68.  TRUE,10000000L,NULL,NULL,NULL,-1L,0L,0L,
  69.  TRUE,10000000L,NULL,NULL,NULL,-1L,0L,0L,
  70.  TRUE,10000000L,NULL,NULL,NULL,-1L,0L,0L,
  71. };
  72.  
  73. UWORD Active;
  74. UWORD MotorCNT[6]={0,0,0,0,0,0};
  75.  
  76. UBYTE *TransferPort="ATUtilities Disk Transfer";
  77. UBYTE *PrefsName="AT:Prefs/DiskTransfer.prefs";
  78. UBYTE *HelpName="AT:Help/DiskTransfer.help";
  79.  
  80. LONG  JanusSignal;
  81. LONG  PortSignal;
  82. LONG  TaskSignal;
  83. ULONG JanusSignalMask;
  84. ULONG PortSignalMask;
  85. ULONG WaitSignalMask;
  86. ULONG TaskSignalMask;
  87. ULONG AppSignalMask;
  88. ULONG Signale;
  89.  
  90. struct JanusBase *JanusBase;
  91. struct Library   *GfxBase;
  92. struct Library   *IntuitionBase;
  93. struct Library   *ATUtilitiesBase;
  94.  
  95. struct Process      *MotorTask;
  96. struct Task         *MainTask;
  97. struct MsgPort      *TaskPort,*ReplyPort;
  98. struct ExtSetupSig  *ExtSetupSig;
  99. struct Window       *WindowPtr;
  100. struct RastPort     *rp;
  101. struct CommMemory   *jhbyte,*jhword;
  102. struct AppManager   *app;
  103. struct Message       Message;
  104. struct Message      *AppMessage;
  105.  
  106. #ifdef SHAREWARE
  107. VOID RegCheck();
  108. #endif
  109. VOID HandleInt();
  110. VOID WriteCache();
  111. VOID ShowInfo();
  112. VOID Motor();
  113. VOID EditiereLW();
  114. VOID ZeigeLW();
  115. BOOL EinstellungenAendern();
  116. BOOL AddCache();
  117. VOID InstallAll();
  118. VOID UninstallAll();
  119. VOID InstallFile();
  120. VOID UninstallFile();
  121. VOID InstallDevice();
  122. VOID UninstallDevice();
  123. VOID OpenAll();
  124. VOID CloseAll();
  125. VOID Bearbeite();
  126. VOID BearbeiteFile();
  127. WORD ChangeCheck();
  128. VOID CalcFAT();
  129. VOID MotorOnOff();
  130. VOID Format();
  131. VOID Kopiere();
  132.  
  133. UBYTE           *mem;
  134. struct MsgPort  *Port;
  135.  
  136.  
  137. /* Installationsroutine */
  138. VOID main()
  139. {
  140.  REGISTER UWORD i;
  141.  REGISTER BOOL  bool;
  142.  
  143.  OpenAll();
  144.  bool=FALSE;
  145.  while(bool==FALSE)
  146.   {
  147.    printf("w %lx",WaitSignalMask);
  148.    Signale=Wait(WaitSignalMask);
  149.    puts("sr");
  150.    if(Signale & PortSignalMask)
  151.     {
  152.      puts("ATKeyboard");
  153.      i=Received(Port);
  154.      switch(i)
  155.       {
  156.        case UTILITY_CALL:
  157.          bool=EinstellungenAendern();
  158.         break;
  159.        case UTILITY_QUIT:
  160.          bool=ExitWarning();
  161.         break;
  162.        case UTILITY_INFO:
  163.          ShowInfo();
  164.         break;
  165.        case UTILITY_HELP:
  166.          Help(HelpName,0);
  167.         break;
  168.       }
  169.     }
  170.    if(Signale & JanusSignalMask)
  171.     {
  172.      HandleInt();
  173.     }
  174.    if(Signale & TaskSignalMask)
  175.     {
  176.      for(i=0;i<6;i++)
  177.       {
  178.        if(MotorCNT[i]>0)
  179.         {
  180.          MotorCNT[i]--;
  181.          if(MotorCNT[i]==0)
  182.           {
  183.            printf("MOTOR %ld\n",i);
  184.            WriteCache(i);
  185.            MotorOnOff(i,0);
  186.            printf("``````````````````\n");
  187.           }
  188.         }
  189.       }
  190.     }
  191.    if(app!=NULL)
  192.     {
  193.      if(Signale & AppSignalMask)
  194.       {
  195.        AppMessage=GetMsg(app->Port);
  196.        if(AppMessage!=NULL)
  197.         {
  198.          ReplyMsg(AppMessage);
  199.          bool=EinstellungenAendern();
  200.         }
  201.       }
  202.     }
  203.   }
  204.  CloseAll();
  205. }
  206.  
  207.  
  208. /* PC-Befehle ausführen */
  209. VOID HandleInt()
  210. {
  211.  REGISTER BOOL  bool;
  212.  REGISTER UWORD i,l;
  213.  REGISTER ULONG o;
  214.  
  215.  printf("C%ld\n",jhword->Arg1);
  216.  switch(jhword->Arg1)
  217.   {
  218.    case 1:
  219.      if(ud[Active].File==FALSE)
  220.       {
  221.        l=jhword->Arg2*512;
  222.        o=jhword->Arg3*512;
  223.        bool=AddCache(&jhword->Memory,o,l);
  224.        if(bool==FALSE)
  225.         {
  226.          puts("W-ERROR");
  227.          MotorCNT[Active]=ud[Active].Motor;
  228.          td[Active].Request->io_Data=mem;
  229.          CopyMemQuick(&jhword->Memory,mem,l);
  230.          td[Active].Request->io_Data=mem;
  231.          td[Active].Request->io_Length=l;
  232.          td[Active].Request->io_Offset=o;
  233.          td[Active].Request->io_Command=CMD_WRITE;
  234.          i=DoIO(td[Active].Request);
  235.          if(i!=0)
  236.           {
  237.            switch(i)
  238.             {
  239.              case 28:
  240.                jhword->Arg2=0+BIT15;
  241.               break;
  242.              case 29:
  243.                jhword->Arg2=15+BIT15;
  244.               break;
  245.              default:
  246.                jhword->Arg2=10+BIT15;
  247.               break;
  248.             }
  249.           }
  250.          else
  251.           {
  252.            jhword->Arg2=0;
  253.           }
  254.          td[Active].Request->io_Command=CMD_UPDATE;
  255.          i=DoIO(td[Active].Request);
  256.          if(i!=0)
  257.           {
  258.            switch(i)
  259.             {
  260.              case 28:
  261.                jhword->Arg2=0+BIT15;
  262.               break;
  263.              case 29:
  264.                jhword->Arg2=15+BIT15;
  265.               break;
  266.              default:
  267.                jhword->Arg2=10+BIT15;
  268.               break;
  269.             }
  270.           }
  271.          else
  272.           {
  273.            jhword->Arg2=0;
  274.           }
  275.         }
  276. /*       puts("ok1"); */
  277.       }
  278.      else
  279.       {
  280.        l=jhword->Arg2*512;
  281.        Seek(td[Active].FileHandle,jhword->Arg3*512,OFFSET_BEGINNING);
  282.        i=Write(td[Active].FileHandle,&jhword->Memory,l);
  283.        if(i==l)
  284.         {
  285.          jhword->Arg2=0;
  286.         }
  287.        else
  288.         {
  289.          jhword->Arg2=10+BIT15;
  290.         }
  291.       }
  292.     break;
  293.    case 2:
  294.      if(ud[Active].File==FALSE)
  295.       {
  296.        puts("READ");
  297.        WriteCache(Active);
  298.        MotorCNT[Active]=ud[Active].Motor;
  299.        td[Active].Request->io_Data=mem;
  300.        l=jhword->Arg2*512;
  301.        td[Active].Request->io_Length=l;
  302.        td[Active].Request->io_Offset=jhword->Arg3*512;
  303.        td[Active].Request->io_Command=CMD_READ;
  304.        i=DoIO(td[Active].Request);
  305.        if(i!=0)
  306.         {
  307.          switch(i)
  308.           {
  309.            case 29:
  310.              jhword->Arg2=15+BIT15;
  311.             break;
  312.            default:
  313.              jhword->Arg2=11+BIT15;
  314.             break;
  315.           }
  316.         }
  317.        else
  318.         {
  319.          CopyMemQuick(mem,&jhword->Memory,l);
  320.          jhword->Arg2=0;
  321.         }
  322.       }
  323.      else
  324.       {
  325.        l=jhword->Arg2*512;
  326.        Seek(td[Active].FileHandle,jhword->Arg3*512,OFFSET_BEGINNING);
  327.        i=Read(td[Active].FileHandle,&jhword->Memory,l);
  328.        if(i==l)
  329.         {
  330.          jhword->Arg2=0;
  331.         }
  332.        else
  333.         {
  334.          jhword->Arg2=15+BIT15;
  335.         }
  336.       }
  337.     break;
  338.    case 3:
  339.      if(ud[Active].File==FALSE)
  340.       {
  341.        MotorCNT[Active]=ud[Active].Motor;
  342.        td[Active].Request->io_Command=CMD_UPDATE;
  343.  
  344.  
  345.  
  346. /*
  347.  
  348.       i=DoIO(td[Active].Request);
  349. */
  350.  
  351.          i=0;
  352.  
  353.        if(i!=0)
  354.         {
  355.          switch(i)
  356.           {
  357.            case 28:
  358.              jhword->Arg2=0+BIT15;
  359.             break;
  360.            case 29:
  361.              jhword->Arg2=15+BIT15;
  362.             break;
  363.            default:
  364.              jhword->Arg2=10+BIT15;
  365.             break;
  366.           }
  367.         }
  368.        else
  369.         {
  370.          jhword->Arg2=0;
  371.         }
  372.       }
  373.     break;
  374.    case 4:
  375.      if(ud[Active].File==FALSE)
  376.       {
  377.        jhword->Arg2=ChangeCheck(Active);
  378.       }
  379.      else
  380.       {
  381.        jhword->Arg2=1;
  382.       }
  383.     break;
  384.    case 5:
  385.      jhword->Arg2=ud[Active].Tracks*ud[Active].Heads*ud[Active].SectorsPerTrack;
  386.      jhword->Arg3=ud[Active].Tracks;
  387.      jhword->Arg4=ud[Active].Heads;
  388.      CalcFAT(Active);
  389.      if(ud[Active].File==FALSE) jhword->Arg7=0; else jhword->Arg7=1;
  390.     break;
  391.    case 6:
  392.      for(i=0;i<6;i++)
  393.       {
  394.        MotorOnOff(i,1);
  395.        MotorCNT[i]=ud[Active].Motor;
  396.       }
  397.     break;
  398.    case 10:
  399.      Format();
  400.     break;
  401.    case 20:
  402.      Kopiere();
  403.     break;
  404.    case 100:
  405.      if(td[jhword->Arg2].Valid==FALSE)
  406.       {
  407.        jhword->Arg2=2+BIT15;
  408.       }
  409.      else
  410.       {
  411.        Active=jhword->Arg2;
  412.        jhword->Arg2=0;
  413.       }
  414.     break;
  415.    default:
  416.     break;
  417.   }
  418.  SendJanusInt(29);
  419.  printf("~~~~~~~~~~~~~~~~~~~~~\n");
  420. }
  421.  
  422.  
  423. /* Diskettenwechsel prüfen */
  424. WORD ChangeCheck(num)
  425.  UWORD num;
  426. {
  427.  REGISTER LONG i;
  428.  
  429.  td[num].Request->io_Command=TD_CHANGENUM;
  430.  DoIO(td[num].Request);
  431.  i=td[num].Request->io_Actual;
  432.  if(i!=td[num].Changes)
  433.   {
  434.    td[num].Changes=i;
  435.    return(0xFF);
  436.   }
  437.  return(1);
  438. }
  439.  
  440.  
  441. /* Laufwerke öffnen */
  442. VOID InstallAll()
  443. {
  444.  REGISTER LONG i;
  445.  
  446.  for(i=0;i<6;i++)
  447.   {
  448.    if(ud[i].File==FALSE)
  449.     {
  450.      InstallDevice(i);
  451.     }
  452.    else
  453.     {
  454.      InstallFile(i);
  455.     }
  456.   }
  457. }
  458.  
  459.  
  460. /* Laufwerke schließen */
  461. VOID UninstallAll()
  462. {
  463.  REGISTER LONG i;
  464.  
  465.  for(i=0;i<6;i++)
  466.   {
  467.    if(ud[i].File==FALSE)
  468.     {
  469.      UninstallDevice(i);
  470.     }
  471.    else
  472.     {
  473.      UninstallFile(i);
  474.     }
  475.   }
  476. }
  477.  
  478.  
  479. VOID InstallDevice(num)
  480.  UWORD num;
  481. {
  482.  
  483.  td[num].Port=CreatePort(0L,0L);
  484.  if(td[num].Port!=NULL)
  485.   {
  486.    td[num].Request=CreateExtIO(td[num].Port,200);
  487.    if(td[num].Request!=NULL)
  488.     {
  489.      td[num].Device=OpenDevice(&ud[num].Name,ud[num].Unit,td[num].Request,0);
  490.      if(td[num].Device!=0)
  491.       {
  492.        UninstallDevice(num);
  493.       }
  494.     }
  495.    else
  496.     {
  497.      UninstallDevice(num);
  498.     }
  499.   }
  500.  else
  501.   {
  502.    UninstallDevice(num);
  503.   }
  504. }
  505.  
  506.  
  507. VOID UninstallDevice(num)
  508.  UWORD num;
  509. {
  510.  
  511.  if(td[num].Valid==TRUE)
  512.   {
  513.    if(td[num].Device==0L) CloseDevice(td[num].Request);
  514.    if(td[num].Request) DeleteExtIO(td[num].Request);
  515.    if(td[num].Port) DeletePort(td[num].Port);
  516.    td[num].Valid=FALSE;
  517.   }
  518. }
  519.  
  520.  
  521. /* Datei installieren */
  522. VOID InstallFile(num)
  523.  UWORD num;
  524. {
  525.  REGISTER ULONG            i,j;
  526.  register struct FileLock *lock;
  527.  
  528.  td[num].Valid=FALSE;
  529.  lock=Lock(&ud[num].Name,ACCESS_READ);
  530.  if(lock!=NULL)
  531.   {
  532.    UnLock(lock);
  533.    td[num].FileHandle=Open(&ud[num].Name,MODE_READWRITE);
  534.    if(td[num].FileHandle!=NULL)
  535.     {
  536.      Seek(td[num].FileHandle,0,OFFSET_END);
  537.      i=Seek(td[num].FileHandle,0,OFFSET_BEGINNING);
  538.      j=512L*(ULONG)ud[num].Tracks*(ULONG)ud[num].Heads*(ULONG)ud[num].SectorsPerTrack;
  539.      if(i!=j)
  540.       {
  541.        MultiRequest("Inkompatible Dateilänge bei LW-Datei",&ud[num].Name,"Okay",NULL);
  542.        Close(td[num].FileHandle);
  543.       }
  544.      else
  545.       {
  546.        td[num].Valid=TRUE;
  547.       }
  548.     }
  549.   }
  550. }
  551.  
  552.  
  553. VOID UninstallFile(num)
  554.  UWORD num;
  555. {
  556.  
  557.  if(td[num].Valid==TRUE)
  558.   {
  559.    if(td[num].FileHandle) Close(td[num].FileHandle);
  560.    td[num].Valid=FALSE;
  561.   }
  562. }
  563.  
  564.  
  565. /* Installationsroutine */
  566. VOID OpenAll()
  567. {
  568.  REGISTER UWORD              i;
  569.  register struct MsgPort    *p;
  570.  register struct FileHandle *fh;
  571.  
  572.  ATUtilitiesBase=OpenLibrary("at-utilities.library",0L);
  573.  if(ATUtilitiesBase==NULL)
  574.   {
  575.    printf("Kann ATUtilities-Library nicht öffnen.\n");
  576.    CloseAll();
  577.   }
  578.  
  579.  GfxBase=OpenLibrary("graphics.library",0L);
  580.  IntuitionBase=OpenLibrary("intuition.library",0L);
  581.  if((GfxBase==NULL)||(IntuitionBase==NULL))
  582.   {
  583.    CloseAll();
  584.   }
  585.  
  586.  p=FindPort(TransferPort);
  587.  if(p!=NULL)
  588.   {
  589.    InfoRequest("ATUtilities Disk Transfer ist schon aktiv.");
  590.    CloseAll();
  591.   }
  592.  
  593.  MainTask=FindTask(NULL);
  594.  SetTaskPri(MainTask,10);
  595.  
  596.  JanusBase=OpenLibrary("janus.library",0L);
  597.  if(JanusBase==NULL)
  598.   {
  599.    ErrorRequest(ERROR_JANUS);
  600.    CloseAll();
  601.   }
  602.  
  603.  TaskSignal=AllocSignal(-1L);
  604.  if(TaskSignal==-1L)
  605.   {
  606.    ErrorRequest(ERROR_SIGNAL);
  607.    CloseAll();
  608.   }
  609.  
  610.  Port=CreatePort(TransferPort,0L);
  611.  if(Port==NULL)
  612.   {
  613.    ErrorRequest(ERROR_MPORT);
  614.    CloseAll();
  615.   }
  616.  
  617.  fh=Open(PrefsName,MODE_OLDFILE);
  618.  if(fh!=NULL)
  619.   {
  620.    Read(fh,&ud,sizeof(struct UDevice)*6);
  621.    Close(fh);
  622.   }
  623.  
  624.  InstallAll();
  625.  
  626.  mem=AllocMem(PUBLIC_PAGESIZE,MEMF_CHIP|MEMF_CLEAR|MEMF_PUBLIC);
  627.  if(mem==NULL)
  628.   {
  629.    ErrorRequest(ERROR_ALLOC);
  630.    CloseAll();
  631.   }
  632.  
  633.  ExtSetupSig=CreatePublicHandler(29);
  634.  if(ExtSetupSig==NULL)
  635.   {
  636.    CloseAll();
  637.   }
  638.  
  639.  TaskPort=CreatePort("Disk Transfer Motor Task <Stop>",0L);
  640.  ReplyPort=CreatePort("Disk Transfer <Stop> Reply",0L);
  641.  if((TaskPort==NULL)||(ReplyPort==NULL))
  642.   {
  643.    ErrorRequest(ERROR_PORT);
  644.    CloseAll();
  645.   }
  646.  
  647.  MotorTask=CreateProcess(Motor,500,"Disk Transfer Motor Task",2);
  648.  if(MotorTask==NULL)
  649.   {
  650.    DeletePort(TaskPort);
  651.    InfoRequest("Kann Motor-Task nicht erstellen.\n");
  652.    CloseAll();
  653.   }
  654.  
  655.  app=CreateAppItem("ATUtilities Disk Transfer");
  656.  if(app!=NULL) AppSignalMask=app->SignalMask; else AppSignalMask=0;
  657.  
  658.  jhword=ExtSetupSig->WordAccess;
  659.  jhbyte=ExtSetupSig->ByteAccess;
  660.  PortSignal=Port->mp_SigBit;
  661.  PortSignalMask=(1L<<PortSignal);
  662.  JanusSignal=ExtSetupSig->JanusSignal;
  663.  JanusSignalMask=ExtSetupSig->JanusSignalMask;
  664.  TaskSignalMask=(1L<<TaskSignal);
  665.  WaitSignalMask=PortSignalMask+JanusSignalMask+TaskSignalMask+AppSignalMask;
  666. }
  667.  
  668.  
  669. /* Programmende */
  670. VOID CloseAll()
  671. {
  672.  if(app) DeleteAppItem(app);
  673.  if(MotorTask!=NULL)
  674.   {
  675.    Message.mn_Node.ln_Type=NT_MESSAGE;
  676.    Message.mn_ReplyPort=ReplyPort;
  677.    PutMsg(TaskPort,&Message);
  678.    WaitPort(ReplyPort);
  679.    DeletePort(ReplyPort);
  680.   }
  681.  if(ExtSetupSig) DeletePublicHandler(ExtSetupSig);
  682.  if(mem) FreeMem(mem,PUBLIC_PAGESIZE);
  683.  if(TaskSignal!=-1) FreeSignal(TaskSignal);
  684.  if(Port) DeletePort(Port);
  685.  UninstallAll();
  686.  if(ATUtilitiesBase) CloseLibrary(ATUtilitiesBase);
  687.  if(GfxBase) CloseLibrary(GfxBase);
  688.  if(IntuitionBase) CloseLibrary(IntuitionBase);
  689.  if(JanusBase) CloseLibrary(JanusBase);
  690.  exit(0);
  691. }
  692.  
  693.  
  694. /* Einstellungs-Fenster */
  695. BOOL EinstellungenAendern()
  696. {
  697.  UBYTE                        text[40];
  698.  BOOL                         bool,ende;
  699.  REGISTER ULONG               Class;
  700.  REGISTER WORD                i,j,id;
  701.  register struct Window       *win;
  702.  register struct RastPort     *rp;
  703.  register struct Gadget       *gad;
  704.  register struct IntuiMessage *msg;
  705.  register struct TextFont     *opal;
  706.  
  707. #ifdef SHAREWARE
  708.  RegCheck();
  709. #endif
  710.  win=CreateStdWindow("ATUtilities - Disk Transfer Einstellungen",
  711.                      75,75,450,122,CLOSEWINDOW|GADGETUP,
  712.                      ACTIVATE|WINDOWDEPTH|WINDOWDRAG|WINDOWCLOSE);
  713.  ende=FALSE;
  714.  if(win!=NULL)
  715.   {
  716.    rp=win->RPort;
  717.    opal=GetOpalFont();
  718.    SetFont(rp,opal);
  719.  
  720.    CreateBoolGadget(win,10,15,155,12,"Einstellungen Okay",1);
  721.    CreateBoolGadget(win,170,15,155,12,"Programm beenden",2);
  722.    CreateBoolGadget(win,335,15,50,12,"Info",3);
  723.    CreateBoolGadget(win,390,15,50,12,"Hilfe",4);
  724.    for(i=0,j=10;i<6;i++,j++)
  725.     {
  726.      sprintf(&text,"Laufwerk %ld:",i+1);
  727.      CreateBoolGadget(win,33,35+(i*14),120,12,&text,j);
  728.      CreateBoolGadget(win,10,35+(i*14),20,12,"!",i+100);
  729.      ZeigeLW(rp,i);
  730.     }
  731.  
  732.    bool=FALSE;
  733.    while(bool==FALSE)
  734.     {
  735.      WaitPort(win->UserPort);
  736.      msg=GetMsg(win->UserPort);
  737.      Class=msg->Class;
  738.      gad=msg->IAddress;
  739.      ReplyMsg(msg);
  740.      switch(Class)
  741.       {
  742.        case GADGETUP:
  743.          id=gad->GadgetID;
  744.          switch(id)
  745.           {
  746.            case 1:
  747.              bool=TRUE;
  748.             break;
  749.            case 2:
  750.              ende=TRUE; bool=TRUE;
  751.             break;
  752.            case 3:
  753.              ShowInfo();
  754.             break;
  755.            case 4:
  756.              Help(HelpName,0);
  757.             break;
  758.            default:
  759.              if((id>=10)&&(id<=15))
  760.               {
  761.                j=id-10;
  762.                EditiereLW(j);
  763.                ZeigeLW(rp,j);
  764.               }
  765.              if((id>=100)&&(id<=105))
  766.               {
  767.                j=id-100;
  768.                if(ud[j].File==FALSE)
  769.                 {
  770.                  if(td[j].Valid==TRUE)
  771.                   {
  772.                    Bearbeite(j);
  773.                   }
  774.                  else
  775.                   {
  776.                    MultiRequest("Dieses Device ist nocht nicht verfügbar.",
  777.                                 "Bitte prüfen Sie die Einstellungen.","Okay",0L);
  778.                   }
  779.                 }
  780.                else
  781.                 {
  782.                  BearbeiteFile(j);
  783.                 }
  784.               }
  785.             break;
  786.           }
  787.         break;
  788.        case CLOSEWINDOW:
  789.          bool=TRUE;
  790.         break;
  791.       }
  792.     }
  793.  
  794.    DeleteStdWindow(win);
  795.   }
  796.  if(ende) ende=ExitWarning();
  797.  return(ende);
  798. }
  799.  
  800.  
  801. /* Parameter ändern */
  802. VOID EditiereLW(num)
  803.  UWORD num;
  804. {
  805.  UBYTE                         text[10];
  806.  BOOL                          ende,f;
  807.  ULONG                         a,b,c,d;
  808.  REGISTER ULONG                Class;
  809.  REGISTER WORD                 i,j,id;
  810.  UBYTE                        *bDevice,
  811.                               *bUnit,
  812.                               *bBlocksPerTrack,
  813.                               *bTracks,
  814.                               *bHeads,
  815.                               *bMotor;
  816.  register struct Window       *win;
  817.  register struct RastPort     *rp;
  818.  register struct IntuiMessage *msg;
  819.  register struct TextFont     *opal;
  820.  register struct Gadget       *gad,*isFile;
  821.  struct FileHandle            *fh;
  822.  
  823.  win=CreateStdWindow("Laufwerksparameter editieren",
  824.                      225,90,400,100,CLOSEWINDOW|GADGETUP,
  825.                      ACTIVATE|WINDOWDEPTH|WINDOWDRAG|WINDOWCLOSE);
  826.  ende=FALSE;
  827.  if(win!=NULL)
  828.   {
  829.    rp=win->RPort;
  830.    opal=GetOpalFont();
  831.    SetFont(rp,opal);
  832.  
  833.    CreateBoolGadget(win,10,15,100,12,"Okay",1);
  834.    CreateBoolGadget(win,120,15,100,12,"Abbruch",2);
  835.  
  836.    if(ud[num].File==FALSE)
  837.     {
  838.      isFile=CreateNToggleGadget(win,300,15,80,12,"Als Datei",100);
  839.     }
  840.    else
  841.     {
  842.      isFile=CreateSToggleGadget(win,300,15,80,12,"Als Datei",100);
  843.     }
  844.  
  845.    bDevice=CreateStringGadget(win,120,30,260,10,&ud[num].Name,100,3);
  846.    sprintf(&text,"%ld",ud[num].Unit);
  847.    bUnit=CreateIntegerGadget(win,120,45,60,10,&text,4,4);
  848.    sprintf(&text,"%ld",ud[num].Heads);
  849.    bHeads=CreateIntegerGadget(win,320,45,60,10,&text,5,5);
  850.    sprintf(&text,"%ld",ud[num].Tracks);
  851.    bTracks=CreateIntegerGadget(win,120,57,60,10,&text,7,6);
  852.    sprintf(&text,"%ld",ud[num].SectorsPerTrack);
  853.    bBlocksPerTrack=CreateIntegerGadget(win,320,57,60,10,&text,5,7);
  854.    sprintf(&text,"%ld",ud[num].Motor);
  855.    bMotor=CreateIntegerGadget(win,320,74,60,10,&text,5,8);
  856.  
  857.    WriteText(rp,15,37,"Device/Datei:");
  858.    WriteText(rp,15,52,"Unit:");
  859.    WriteText(rp,220,52,"S/L-Köpfe:");
  860.    WriteText(rp,15,64,"Spuren:");
  861.    WriteText(rp,220,64,"Sekt./Spur:");
  862.    WriteText(rp,15,82,"Motor-Ausschaltzeit nach x Sekunden:");
  863.  
  864.    ende=FALSE;
  865.    while(ende==FALSE)
  866.     {
  867.      WaitPort(win->UserPort);
  868.      msg=GetMsg(win->UserPort);
  869.      Class=msg->Class;
  870.      gad=msg->IAddress;
  871.      ReplyMsg(msg);
  872.      switch(Class)
  873.       {
  874.        case GADGETUP:
  875.          id=gad->GadgetID;
  876.          switch(id)
  877.           {
  878.            case 2:
  879.              ende=TRUE;
  880.             break;
  881.            case 1:
  882.              j=0;
  883.              a=atol(bUnit);
  884.              b=atol(bTracks);
  885.              c=atol(bHeads);
  886.              d=atol(bBlocksPerTrack);
  887.              i=atol(bMotor);
  888.              if(isFile->Flags & SELECTED) f=TRUE; else f=FALSE;
  889.              if(b<2)
  890.               { InfoRequest("Unzulässige Spurenanzahl."); j=1; }
  891.              if(c<1)
  892.               { InfoRequest("Unzulässige S/L-Kopfanzahl."); j++; }
  893.              if(d<2)
  894.               { InfoRequest("Unzulässige Anzahl von Sektoren/Spur."); j++; }
  895.              if(i>180)
  896.               { InfoRequest("Motor-Zeit nicht empfehlenswert (>180s)."); }
  897.              if(j==0)
  898.               {
  899.                if(strcmp(&ud[num].Name,bDevice)) j=1;
  900.                if(ud[num].Unit!=a) j=1;
  901.                if(ud[num].Tracks!=b) j=1;
  902.                if(ud[num].Heads!=c) j=1;
  903.                if(ud[num].SectorsPerTrack!=d) j=1;
  904.                strcpy(&ud[num].Name,bDevice);
  905.                ud[num].Motor=i;
  906.                ud[num].Unit=a;
  907.                ud[num].Tracks=b;
  908.                ud[num].Heads=c;
  909.                ud[num].SectorsPerTrack=d;
  910.                ud[num].File=f;
  911.                if(j==1)
  912.                 {
  913.                  td[num].Valid=FALSE;
  914.                  MultiRequest("Um Probleme mit MS-DOS zu vermeiden, wird",
  915.                               "das Laufwerk erst nach einem Reset aktiv.",
  916.                               "Okay",NULL);
  917.                 }
  918.                fh=Open(PrefsName,MODE_NEWFILE);
  919.                if(fh!=NULL)
  920.                 {
  921.                  Write(fh,&ud,sizeof(struct UDevice)*6);
  922.                  Close(fh);
  923.                 }
  924.                else
  925.                 {
  926.                  InfoRequest("Fehler beim Schreiben der Prefs-Datei.");
  927.                 }
  928.                ende=TRUE;
  929.               }
  930.             break;
  931.           }
  932.         break;
  933.        case CLOSEWINDOW:
  934.          ende=TRUE;
  935.         break;
  936.       }
  937.     }
  938.    DeleteStdWindow(win);
  939.   }
  940. }
  941.  
  942.  
  943. /* Parameter anzeigen */
  944. VOID ZeigeLW(rp,id)
  945.  struct RastPort *rp;
  946.  UWORD            id;
  947. {
  948.  UBYTE          size[20];
  949.  UBYTE          text[30];
  950.  REGISTER ULONG kb;
  951.  
  952.  kb=(ud[id].Heads*ud[id].Tracks*ud[id].SectorsPerTrack*512)/1024;
  953.  if(kb>=10000)
  954.   {
  955.    sprintf(&size,"%ld MB",kb/1024);
  956.   }
  957.  else
  958.   {
  959.    sprintf(&size,"%ld KB",kb);
  960.   }
  961.  if(ud[id].File==FALSE)
  962.   {
  963.    sprintf(&text,"%s  %s  Unit %ld",
  964.                   &size,&ud[id].Name,ud[id].Unit);
  965.   }
  966.  else
  967.   {
  968.    sprintf(&text,"%s  %s",&size,&ud[id].Name);
  969.   }
  970.  WriteText(rp,160,43+(id*14),&text);
  971. }
  972.  
  973.  
  974. /* Device-Laufwerk bearbeiten */
  975. VOID Bearbeite(num)
  976.  UWORD num;
  977. {
  978.  UBYTE                         text[40];
  979.  REGISTER BOOL                 ende,bool;
  980.  REGISTER ULONG                Class;
  981.  REGISTER WORD                 i,j,id;
  982.  register struct Window       *win;
  983.  register struct RastPort     *rp;
  984.  register struct Gadget       *gad;
  985.  register struct IntuiMessage *msg;
  986.  register struct TextFont     *opal;
  987.  register struct Gadget       *verify;
  988.  BOOL                          v;
  989.  ULONG                         BytesPerTrack;
  990.  ULONG                         Track;
  991.  UBYTE                        *FormatMemory;
  992.  
  993.  win=CreateStdWindow("Speichermedium bearbeiten",
  994.                      225,90,300,76,CLOSEWINDOW|GADGETUP,
  995.                      ACTIVATE|WINDOWDEPTH|WINDOWDRAG|WINDOWCLOSE);
  996.  ende=FALSE;
  997.  if(win!=NULL)
  998.   {
  999.    rp=win->RPort;
  1000.    opal=GetOpalFont();
  1001.    SetFont(rp,opal);
  1002.  
  1003.    CreateBoolGadget(win,10,12,100,12,"Okay",1);
  1004.    CreateBoolGadget(win,10,30,119,12,"Hard-Format",2);
  1005.    CreateBoolGadget(win,10,44,172,12,"Prüfe auf Fehler",3);
  1006.    verify=CreateSToggleGadget(win,132,30,50,12,"Verify",100);
  1007.    DrawNTextBorder(win,10,58,280,12,"Kein Fehler aufgetreten.");
  1008.    DrawNTextBorder(win,190,30,100,12,"0");
  1009.    DrawNTextBorder(win,190,44,100,12,"0 %");
  1010.  
  1011.    ende=FALSE;
  1012.    while(ende==FALSE)
  1013.     {
  1014.      WaitPort(win->UserPort);
  1015.      msg=GetMsg(win->UserPort);
  1016.      Class=msg->Class;
  1017.      gad=msg->IAddress;
  1018.      ReplyMsg(msg);
  1019.      switch(Class)
  1020.       {
  1021.        case GADGETUP:
  1022.          id=gad->GadgetID;
  1023.          switch(id)
  1024.           {
  1025.            case 2:
  1026.            case 3:
  1027.              DrawCNTextBorder(win,10,58,280,12,"Kein Fehler aufgetreten.");
  1028.              if(verify->Flags & SELECTED) v=TRUE; else v=FALSE;
  1029.              if(id==3)
  1030.               {
  1031.                bool=MultiRequest("Wollen Sie den Datenträger auf",
  1032.                                  "Fehler überprüfen ?",
  1033.                                  "Ja, Prüfen","Nein, Zurück");
  1034.               }
  1035.              else
  1036.               {
  1037.                bool=MultiRequest("Hard-Format: Alle Daten werden gelöscht!",
  1038.                                  "Sind Sie wirklich sicher ?",
  1039.                                  "Ja, Format","NEIN! Zurück");
  1040.               }
  1041.              if(bool==TRUE)
  1042.               {
  1043.                MotorCNT[num]=5;
  1044.                BytesPerTrack=ud[num].SectorsPerTrack*ud[num].Heads*512;
  1045.                FormatMemory=AllocMem(BytesPerTrack,MEMF_CHIP|MEMF_CLEAR|MEMF_PUBLIC);
  1046.                if(FormatMemory!=NULL)
  1047.                 {
  1048.                  SetDrMd(rp,JAM2);
  1049.                  j=0;
  1050.                  for(Track=0;Track<ud[num].Tracks;Track++)
  1051.                   {
  1052.                    sprintf(&text,"   %ld   ",Track);
  1053.                    DrawNTextBorder(win,190,30,100,12,&text);
  1054.                    sprintf(&text,"   %3ld %%   ",((Track*100)/(ud[num].Tracks-1)));
  1055.                    DrawNTextBorder(win,190,44,100,12,&text);
  1056.                    if(ud[num].File==FALSE)
  1057.                     {
  1058.                      if(id==3)
  1059.                       {
  1060.                        td[num].Request->io_Data=FormatMemory;
  1061.                        td[num].Request->io_Length=BytesPerTrack;
  1062.                        td[num].Request->io_Offset=Track*BytesPerTrack;
  1063.                        td[num].Request->io_Command=CMD_READ;
  1064.                        i=DoIO(td[num].Request);
  1065.                        if(i!=0)
  1066.                         {
  1067.                          if(i==29)
  1068.                           {
  1069.                            InfoRequest("Das Medium ist nicht eingelegt.");
  1070.                            Track=ud[num].Tracks;
  1071.                           }
  1072.                          else
  1073.                           {
  1074.                            sprintf(&text,"Fehler #%ld auf Track %ld.",i,Track);
  1075.                            DrawCNTextBorder(win,10,58,280,12,&text);
  1076.                           }
  1077.                          j++;
  1078.                         }
  1079.                       }
  1080.                      else
  1081.                       {
  1082.                        td[num].Request->io_Data=FormatMemory;
  1083.                        td[num].Request->io_Length=BytesPerTrack;
  1084.                        td[num].Request->io_Offset=Track*BytesPerTrack;
  1085.                        td[num].Request->io_Command=TD_FORMAT;
  1086.                        i=DoIO(td[num].Request);
  1087.                        if(i!=0)
  1088.                         {
  1089.                          sprintf(&text,"Format: Fehler #%ld auf Track %ld.",i,Track);
  1090.                          DrawCNTextBorder(win,10,58,280,12,&text);
  1091.                          j++;
  1092.                          if(i==28)
  1093.                           {
  1094.                            InfoRequest("Das Medium ist schreibgeschützt.");
  1095.                            Track=ud[num].Tracks;
  1096.                           }
  1097.                          else if(i==29)
  1098.                           {
  1099.                            InfoRequest("Das Medium ist nicht eingelegt.");
  1100.                            Track=ud[num].Tracks;
  1101.                           }
  1102.                         }
  1103.                        if((v==TRUE)&&(Track<ud[num].Tracks))
  1104.                         {
  1105.                          td[num].Request->io_Data=FormatMemory;
  1106.                          td[num].Request->io_Length=BytesPerTrack;
  1107.                          td[num].Request->io_Offset=Track*BytesPerTrack;
  1108.                          td[num].Request->io_Command=CMD_READ;
  1109.                          i=DoIO(td[num].Request);
  1110.                          if(i!=0)
  1111.                           {
  1112.                            sprintf(&text,"Verify: Fehler #%ld auf Track %ld.",i,Track);
  1113.                            DrawCNTextBorder(win,10,58,280,12,&text);
  1114.                            j++;
  1115.                           }
  1116.                         }
  1117.                       }
  1118.                     }
  1119.                   }
  1120.                  if(j==0)
  1121.                   {
  1122.                    if(id==3) InfoRequest("Der Datenträger ist fehlerfrei.");
  1123.                   }
  1124.                  else
  1125.                   {
  1126.                    if(id==3)
  1127.                     {
  1128.                      sprintf(&text,"%ld Fehler gefunden worden.",j);
  1129.                      MultiRequest("Bei der Überprüfung sind",&text,"Okay",NULL);
  1130.                     }
  1131.                    else
  1132.                     {
  1133.                      sprintf(&text,"%ld Fehler aufgetreten.",j);
  1134.                      MultiRequest("Bei der Formatierung sind",&text,"Okay",NULL);
  1135.                     }
  1136.                   }
  1137.                  FreeMem(FormatMemory,BytesPerTrack);
  1138.                 }
  1139.               }
  1140.             break;
  1141.            case 1:
  1142.              ende=TRUE;
  1143.             break;
  1144.           }
  1145.         break;
  1146.        case CLOSEWINDOW:
  1147.          ende=TRUE;
  1148.         break;
  1149.       }
  1150.     }
  1151.    DeleteStdWindow(win);
  1152.   }
  1153. }
  1154.  
  1155.  
  1156. /* FAT berechnen */
  1157. VOID CalcFAT(num)
  1158.  UWORD num;
  1159. {
  1160.  REGISTER UWORD anz,i;
  1161.  REGISTER ULONG bytes,plus,sek,spc;
  1162.  
  1163.  
  1164.  sek=ud[num].Tracks*ud[num].Heads*ud[num].SectorsPerTrack;
  1165.  if(sek>4096)
  1166.   {
  1167.    bytes=sek*2;       /* FAT 16-Bit */
  1168.   }
  1169.  else
  1170.   {
  1171.    bytes=(sek*3)/2;   /* FAT 12-Bit */
  1172.   }
  1173.  plus=0;
  1174.  anz=0;
  1175.  for(i=0;i<32000;i++)
  1176.   {
  1177.    if(plus>=bytes)
  1178.     {
  1179.      spc=1;
  1180.      if(anz>15)
  1181.       {
  1182.        do
  1183.         {
  1184.          spc=spc*2;
  1185.          anz=anz/2;
  1186.         } while(anz>15);
  1187.       }
  1188.      jhword->Arg5=anz;
  1189.      jhbyte->Arg6=spc;
  1190.      return;
  1191.     }
  1192.    else
  1193.     {
  1194.      plus+=512;
  1195.      anz++;
  1196.     }
  1197.   }
  1198. }
  1199.  
  1200.  
  1201. /* File-Laufwerk bearbeiten */
  1202. VOID BearbeiteFile(num)
  1203.  UWORD num;
  1204. {
  1205.  UBYTE                       text[35];
  1206.  REGISTER BOOL               bool;
  1207.  REGISTER UBYTE             *mem;
  1208.  REGISTER ULONG              i,j,k,l;
  1209.  register struct FileHandle *fh;
  1210.  register struct Window     *win;
  1211.  register struct RastPort   *rp;
  1212.  struct TextFont            *opal;
  1213.  struct IntuiMessage        *msg;
  1214.  
  1215.  if(td[num].Valid==FALSE)
  1216.   {
  1217.    bool=MultiRequest("Es existiert keine Laufwerksdatei.",
  1218.                      "Möchten Sie eine erstellen ?",
  1219.                      "Ja, Erstellen","Nein, Zurück");
  1220.    if(bool==TRUE)
  1221.     {
  1222.      j=512*ud[num].SectorsPerTrack*ud[num].Heads;
  1223.      mem=AllocMem(j,MEMF_CLEAR|MEMF_PUBLIC);
  1224.      if(mem!=NULL)
  1225.       {
  1226.        fh=Open(&ud[num].Name,MODE_NEWFILE);
  1227.        if(fh!=NULL)
  1228.         {
  1229.          win=CreateStdWindow("Laufwerksdatei erstellen",
  1230.                              75,90,300,30,GADGETUP|CLOSEWINDOW,
  1231.                              WINDOWCLOSE|WINDOWDEPTH|ACTIVATE|WINDOWDRAG);
  1232.          if(win!=NULL)
  1233.           {
  1234.            opal=GetOpalFont();
  1235.            rp=win->RPort;
  1236.            SetFont(rp,opal);
  1237.            CreateBoolGadget(win,10,15,120,12,"Stop !",1);
  1238.            bool=FALSE;
  1239.            if(win!=NULL)
  1240.             {
  1241.              for(i=0;i<ud[num].Tracks;i++)
  1242.               {
  1243.                sprintf(&text,"Track %ld von %ld",i,ud[num].Tracks);
  1244.                DrawCNTextBorder(win,140,15,150,12,&text);
  1245.                k=Write(fh,mem,j);
  1246.                if(k!=j)
  1247.                 {
  1248.                  InfoRequest("Schreibfehler!");
  1249.                  i=ud[num].Tracks;
  1250.                  bool=TRUE;
  1251.                 }
  1252.                msg=GetMsg(win->UserPort);
  1253.                if(msg!=NULL)
  1254.                 {
  1255.                  InfoRequest("Stop!");
  1256.                  i=ud[num].Tracks;
  1257.                  bool=TRUE;
  1258.                 }
  1259.               }
  1260.              if(bool==FALSE)
  1261.               {
  1262.                td[num].FileHandle=fh;
  1263.                td[num].Valid=TRUE;
  1264.               }
  1265.              else
  1266.               {
  1267.                Close(fh);
  1268.                DeleteFile(&ud[num].Name);
  1269.               }
  1270.             }
  1271.            DeleteStdWindow(win);
  1272.           }
  1273.          else
  1274.           {
  1275.            Close(fh);
  1276.            DeleteFile(&ud[num].Name);
  1277.            ErrorRequest(ERROR_ALLOC);
  1278.           }
  1279.         }
  1280.        else InfoRequest("Laufwerksdatei läßt sich nicht erstellen.");
  1281.        FreeMem(mem,j);
  1282.       }
  1283.      else ErrorRequest(ERROR_ALLOC);
  1284.     }
  1285.   }
  1286.  else
  1287.   {
  1288.    win=CreateStdWindow("Laufwerksdatei-Information",75,90,300,90,
  1289.                        CLOSEWINDOW|GADGETUP,
  1290.                        WINDOWCLOSE|WINDOWDEPTH|WINDOWDRAG|ACTIVATE);
  1291.    if(win!=NULL)
  1292.     {
  1293.      opal=GetOpalFont();
  1294.      rp=win->RPort;
  1295.      SetFont(rp,opal);
  1296.      CreateBoolGadget(win,10,15,120,12,"Okay",1);
  1297.  
  1298.      sprintf(&text,"Spuren: %ld",ud[num].Tracks);
  1299.      DrawNTextBorder(win,10,30,280,12,&text);
  1300.      sprintf(&text,"S/L-Köpfe: %ld",ud[num].Heads);
  1301.      DrawNTextBorder(win,10,45,280,12,&text);
  1302.      sprintf(&text,"Sektoren/Spur: %ld",ud[num].SectorsPerTrack);
  1303.      DrawNTextBorder(win,10,60,280,12,&text);
  1304.      sprintf(&text,"KBytes: %ld",(ud[num].Tracks*ud[num].SectorsPerTrack*ud[num].Heads)/2);
  1305.      DrawNTextBorder(win,10,75,280,12,&text);
  1306.  
  1307.      WaitPort(win->UserPort);
  1308.      DeleteStdWindow(win);
  1309.     }
  1310.   }
  1311. }
  1312.  
  1313.  
  1314. /* Motor-Kontrollprozeß */
  1315. VOID Motor()
  1316. {
  1317.  register struct Message *msg;
  1318.  
  1319.  geta4();
  1320.  do
  1321.   {
  1322.    Delay(50);
  1323.    Signal(MainTask,TaskSignalMask);
  1324.    msg=GetMsg(TaskPort);
  1325.   }
  1326.  while(msg==NULL);
  1327.  DeletePort(TaskPort);
  1328.  ReplyMsg(msg);
  1329.  Exit(0);
  1330. }
  1331.  
  1332.  
  1333. /* Motor ein- und ausschalten */
  1334. VOID MotorOnOff(num,status)
  1335.  UWORD num;
  1336.  UWORD status;
  1337. {
  1338.  
  1339.  if(td[num].Valid==TRUE)
  1340.   {
  1341.    if(ud[num].File==FALSE)
  1342.     {
  1343.      td[num].Request->io_Command=TD_MOTOR;
  1344.      td[num].Request->io_Length=status;
  1345.      SendIO(td[num].Request);
  1346.     }
  1347.   }
  1348. }
  1349.  
  1350.  
  1351. /* Datenträger formatieren */
  1352. VOID Format()
  1353. {
  1354.  REGISTER ULONG  tSize;
  1355.  REGISTER UBYTE *fBuffer;
  1356.  REGISTER UWORD  res,i;
  1357.  
  1358.  res=0;
  1359.  if(ud[Active].File==FALSE)
  1360.   {
  1361.    tSize=512*ud[Active].SectorsPerTrack*ud[Active].Heads;
  1362.    fBuffer=AllocMem(tSize,MEMF_CHIP|MEMF_CLEAR|MEMF_PUBLIC);
  1363.    if(fBuffer!=NULL)
  1364.     {
  1365.      td[Active].Request->io_Data=fBuffer;
  1366.      td[Active].Request->io_Length=tSize;
  1367.      td[Active].Request->io_Offset=jhword->Arg2*tSize;
  1368.      td[Active].Request->io_Command=TD_FORMAT;
  1369.      i=DoIO(td[Active].Request);
  1370.      if(i==0)
  1371.       {
  1372.        if(jhword->Arg3==1)
  1373.         {
  1374.          td[Active].Request->io_Command=CMD_READ;
  1375.          i=DoIO(td[Active].Request);
  1376.          if(i!=0) res=3;
  1377.         }
  1378.       } else res=2;
  1379.      MotorCNT[Active]=ud[Active].Motor;
  1380.      FreeMem(fBuffer,tSize);
  1381.     }
  1382.    else res=1;
  1383.   }
  1384.  jhword->Arg2=res;
  1385. }
  1386.  
  1387.  
  1388. /* Datenträger kopieren */
  1389. VOID Kopiere()
  1390. {
  1391.  REGISTER ULONG  tSize;
  1392.  REGISTER UBYTE *fBuffer;
  1393.  REGISTER UWORD  res,i;
  1394.  
  1395.  res=0;
  1396.  tSize=512*ud[Active].SectorsPerTrack*ud[Active].Heads;
  1397.  fBuffer=AllocMem(tSize,MEMF_CHIP|MEMF_CLEAR|MEMF_PUBLIC);
  1398.  if(fBuffer!=NULL)
  1399.   {
  1400.    if(ud[Active].File==FALSE)
  1401.     {
  1402.      td[Active].Request->io_Data=fBuffer;
  1403.      td[Active].Request->io_Length=tSize;
  1404.      td[Active].Request->io_Offset=jhword->Arg2*tSize;
  1405.      td[Active].Request->io_Command=CMD_READ;
  1406.      i=DoIO(td[Active].Request);
  1407.     }
  1408.    else
  1409.     {
  1410.      Seek(td[Active].FileHandle,jhword->Arg2*tSize,OFFSET_BEGINNING);
  1411.      i=Read(td[Active].FileHandle,fBuffer,tSize);
  1412.      if(i!=tSize) i=1; else i=0;
  1413.     }
  1414.    if(i==0)
  1415.     {
  1416.      if(ud[jhword->Arg3].File==FALSE)
  1417.       {
  1418.        td[jhword->Arg3].Request->io_Data=fBuffer;
  1419.        td[jhword->Arg3].Request->io_Length=tSize;
  1420.        td[jhword->Arg3].Request->io_Offset=jhword->Arg2*tSize;
  1421.        td[jhword->Arg3].Request->io_Command=TD_FORMAT;
  1422.        i=DoIO(td[jhword->Arg3].Request);
  1423.        if(i==0)
  1424.         {
  1425.          if(jhword->Arg4==1)
  1426.           {
  1427.            td[jhword->Arg3].Request->io_Command=CMD_READ;
  1428.            i=DoIO(td[jhword->Arg3].Request);
  1429.            if(i!=0) res=4;
  1430.           }
  1431.         } else res=3;
  1432.       }
  1433.      else
  1434.       {
  1435.        Seek(td[jhword->Arg3].FileHandle,jhword->Arg2*tSize,OFFSET_BEGINNING);
  1436.        i=Write(td[jhword->Arg3].FileHandle,fBuffer,tSize);
  1437.        if(i!=tSize) res=3;
  1438.       }
  1439.     } else res=2;
  1440.    MotorCNT[Active]=ud[Active].Motor;
  1441.    MotorCNT[jhword->Arg3]=ud[jhword->Arg3].Motor;
  1442.    FreeMem(fBuffer,tSize);
  1443.   } else res=1;
  1444.  jhword->Arg2=res;
  1445. }
  1446.  
  1447.  
  1448. /* Information */
  1449. VOID ShowInfo()
  1450. {
  1451.  InformationBox("ATUtilities Disk Transfer - Information",
  1452.                 "$VER: Disk Transfer - Version 4.0",
  1453.                 "Copyright (C) 1993 by",
  1454.                 "Thomas Dreibholz",
  1455.                 "All rights reserved.",
  1456.                 "AT:Icons/Utility");
  1457. }
  1458.  
  1459.  
  1460. #ifdef SHAREWARE
  1461. VOID RegCheck()
  1462. {
  1463.  REGISTER BOOL               bool;
  1464.  REGISTER UWORD              i,j;
  1465.  register struct TextFont   *opal;
  1466.  register struct FileHandle *fh;
  1467.  register struct RastPort   *rp;
  1468.  register struct Window     *RegWindow;
  1469.  
  1470.  bool=FALSE;
  1471.  fh=Open("SYS:PC/ATUtilities/ATUtilities.reg",MODE_OLDFILE);
  1472.  if(fh!=NULL)
  1473.   {
  1474.    Read(fh,&Kunde,sizeof(struct Kunde));
  1475.    Close(fh);
  1476.    i=CHECKSTR(&Kunde.Code,&Kunde.Vorname,CODE_VN,VN1);
  1477.    i+=CHECKSTR(&Kunde.Code,&Kunde.Nachname,CODE_NN,NN1);
  1478.    i+=CHECKSTR(&Kunde.Code,&Kunde.Straße,CODE_ST,ST1);
  1479.    i+=CHECKSTR(&Kunde.Code,&Kunde.Land,CODE_LA,LA1);
  1480.    i+=CHECKSTR(&Kunde.Code,&Kunde.Postleitzahl,CODE_PL,PL1);
  1481.    i+=CHECKSTR(&Kunde.Code,&Kunde.Ort,CODE_OR,OR1);
  1482.    i+=CHECKCODE(&Kunde.Code);
  1483.    if(i==0)
  1484.     {
  1485.      j=GETPRG(Kunde.Code);
  1486.      if(j & PROG_DISKTRANSFER) bool=TRUE;
  1487.     }
  1488.   }
  1489.  if(bool==FALSE)
  1490.   {
  1491.    RegWindow=CreateStdWindow(NULL,75,100,450,72,0L,0L);
  1492.    if(RegWindow!=NULL)
  1493.     {
  1494.      rp=RegWindow->RPort;
  1495.      opal=GetOpalFont();
  1496.      SetFont(rp,opal);
  1497.      SelectStdFPen(rp);
  1498.      WriteText(rp,15,10,"Disk Transfer - Unregistrierte Version");
  1499.      WriteText(rp,15,23,"Dieses Programm ist Shareware! Möchten Sie es");
  1500.      WriteText(rp,15,33,"regelmäßig nutzen, so müssen Sie es registrieren");
  1501.      WriteText(rp,15,43,"lassen! Weitere Informationen dazu finden Sie in");
  1502.      WriteText(rp,15,53,"der Datei \"Registrierung.DOK\" und im Hilfe-");
  1503.      WriteText(rp,15,63,"system unter \"Shareware-Registrierung\".");
  1504.      Delay(500);
  1505.      DeleteStdWindow(RegWindow);
  1506.     }
  1507.   }
  1508. }
  1509. #endif
  1510.  
  1511.  
  1512. BOOL AddCache(block,offset,len)
  1513.  UBYTE *block;
  1514.  ULONG  offset;
  1515.  UWORD  len;
  1516. {
  1517.  REGISTER UBYTE             *copy;
  1518.  register struct CacheBlock *cb,*old;
  1519.  
  1520.  if(td[Active].FirstCacheBlock==NULL)
  1521.   {
  1522.    td[Active].Request->io_Command=TD_PROTSTATUS;
  1523.    DoIO(td[Active].Request);
  1524.    if(td[Active].Request->io_Actual!=0) return(FALSE);
  1525.  
  1526.  
  1527. /*   td[Active].Request->io_Command=TD_CHANGENUM;
  1528.    DoIO(td[Active].Request);
  1529.    if(td[Active].Request->io_Actual!=td[Active].Changes) return(FALSE);
  1530. */
  1531.  
  1532.  
  1533.   }
  1534.  
  1535.  if((AvailMem(MEMF_PUBLIC|MEMF_CHIP))<225000) return(FALSE);
  1536.  
  1537. /*
  1538.  cb=AllocRemember(&td[Active].CacheRemember,sizeof(struct CacheBlock),MEMF_PUBLIC|MEMF_CLEAR);
  1539.  if(cb==NULL) return(FALSE);
  1540.  copy=AllocRemember(&td[Active].CacheRemember,len,MEMF_PUBLIC|MEMF_CHIP);
  1541.  if(copy==NULL) return(FALSE);
  1542. */
  1543.  
  1544.  cb=AllocMem(sizeof(struct CacheBlock),MEMF_PUBLIC|MEMF_CLEAR);
  1545.  if(cb==NULL) return(FALSE);
  1546.  copy=AllocMem(len,MEMF_PUBLIC|MEMF_CHIP);
  1547.  if(copy==NULL) return(FALSE);
  1548.  
  1549.  cb->Offset=offset;
  1550.  cb->Length=len;
  1551.  cb->Memory=copy;
  1552.  cb->Changes=td[Active].Changes;
  1553.  CopyMemQuick(block,copy,len);
  1554.  if(td[Active].FirstCacheBlock==NULL)
  1555.    td[Active].FirstCacheBlock=cb;
  1556.  else
  1557.   {
  1558.    old=td[Active].FirstCacheBlock;
  1559.    if(old->NextCacheBlock!=NULL)
  1560.     {
  1561.      while(old->NextCacheBlock!=NULL)
  1562.       old=old->NextCacheBlock;
  1563.     }
  1564.    old->NextCacheBlock=cb;
  1565.   }
  1566.  
  1567.  xxx+=len;
  1568.  
  1569.  
  1570.  printf("ADD:   %lx  L=%ld  O=%ld    xxx=%ld\n",copy,len,offset,xxx);
  1571.  
  1572.  
  1573.  MotorCNT[Active]=2;
  1574.  MotorOnOff(Active,1);
  1575.  jhword->Arg2=0;
  1576.  puts("return");
  1577.  return(TRUE);
  1578. }
  1579.  
  1580.  
  1581. VOID WriteCache(ii)
  1582.  UWORD ii;
  1583. {
  1584.  register struct CacheBlock *cb;
  1585.  
  1586.  printf("AUSGABE %ld\n",ii);
  1587.  if(td[ii].FirstCacheBlock!=NULL)
  1588.   {
  1589.    cb=td[ii].FirstCacheBlock;
  1590.    do
  1591.     {
  1592. /*     if(cb->Changes==td[ii].Changes)
  1593.       { */
  1594.        td[ii].Request->io_Data=cb->Memory;
  1595.        td[ii].Request->io_Offset=cb->Offset;
  1596.        td[ii].Request->io_Length=cb->Length;
  1597.        td[ii].Request->io_Command=CMD_WRITE;
  1598.        printf("WRITE: %lx  L=%ld  O=%ld\n",cb->Memory,cb->Length,cb->Offset);
  1599.        DoIO(td[ii].Request);
  1600.  
  1601.  
  1602.        FreeMem(cb->Memory,cb->Length);
  1603.  
  1604.  
  1605.     /*  } */
  1606.      cb=cb->NextCacheBlock;
  1607.     } while(cb!=NULL);
  1608.  
  1609.    td[ii].Request->io_Command=CMD_UPDATE;
  1610.    DoIO(td[ii].Request);
  1611.  
  1612.  
  1613. /*   FreeRemember(&td[ii].CacheRemember,TRUE); */
  1614.  
  1615.  
  1616.    td[ii].CacheRemember=NULL;
  1617.    td[ii].FirstCacheBlock=NULL;
  1618.    printf("-------------------------- %ld Bytes\n",xxx);
  1619.    xxx=0;
  1620.   }
  1621. }
  1622.  
  1623.